const TOKEN_KEY = "TOKEN__";

export function setToken(val: string) {
  return setAuthCache(TOKEN_KEY, val);
}

export function getToken() {
  return getAuthCache(TOKEN_KEY);
}

export function removeToken() {
  return clearAuthCache(TOKEN_KEY);
}

export function getAuthCache(key: string, addr = "session") {
  if (addr == "session") {
    return sessionStorage.getItem(key);
  } else {
    return localStorage.getItem(key);
  }
}

export function setAuthCache(key: string, value, addr = "session") {
  if (addr == "session") {
    return sessionStorage.setItem(key, value);
  } else {
    return localStorage.setItem(key, value);
  }
}

export function clearAuthCache(key: string, addr = "session") {
  if (addr == "session") {
    return sessionStorage.removeItem(key);
  } else {
    return localStorage.removeItem(key);
  }
}
